﻿namespace KeRui.DAL
{
    using KeRui.DBUtility;
    using KeRui.Model;
    using System;
    using System.Data;
    using System.Data.SqlClient;

    public class CmsCatch
    {
        public int Add(KeRui.Model.CmsCatch model)
        {
            int num;
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@CatchName", SqlDbType.NVarChar, 50), new SqlParameter("@IsUsing", SqlDbType.Int, 4), new SqlParameter("@Url", SqlDbType.VarChar, 0xff), new SqlParameter("@StartPage", SqlDbType.Int, 4), new SqlParameter("@EndPage", SqlDbType.Int, 4), new SqlParameter("@Interval", SqlDbType.Int, 4), new SqlParameter("@NodeID", SqlDbType.Int, 4), new SqlParameter("@Whilelist", SqlDbType.NVarChar), new SqlParameter("@Blacklist", SqlDbType.NVarChar), new SqlParameter("@SavePic", SqlDbType.Int, 4), new SqlParameter("@ParseID", SqlDbType.Int, 4), new SqlParameter("@ContentType", SqlDbType.Int, 4), new SqlParameter("@ContentPlus", SqlDbType.NVarChar) };
            parameters[0].Value = model.CatchName;
            parameters[1].Value = model.IsUsing;
            parameters[2].Value = model.Url;
            parameters[3].Value = model.StartPage;
            parameters[4].Value = model.EndPage;
            parameters[5].Value = model.Interval;
            parameters[6].Value = model.NodeID;
            parameters[7].Value = model.Whilelist;
            parameters[8].Value = model.Blacklist;
            parameters[9].Value = model.SavePic;
            parameters[10].Value = model.ParseID;
            parameters[11].Value = model.ContentType;
            parameters[12].Value = model.ContentPlus;
            return DbHelperSQL.RunProcedure("CmsCatch_ADD", parameters, out num);
        }

        public int Delete(int CatchID)
        {
            int num;
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@CatchID", SqlDbType.Int, 4) };
            parameters[0].Value = CatchID;
            return DbHelperSQL.RunProcedure("CmsCatch_Delete", parameters, out num);
        }

        public KeRui.Model.CmsCatch GetModel(int CatchID)
        {
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@CatchID", SqlDbType.Int, 4) };
            parameters[0].Value = CatchID;
            KeRui.Model.CmsCatch @catch = new KeRui.Model.CmsCatch();
            DataSet set = DbHelperSQL.RunProcedure("CmsCatch_GetModel", parameters, "ds");
            if (set.Tables[0].Rows.Count > 0)
            {
                if (set.Tables[0].Rows[0]["CatchID"].ToString() != "")
                {
                    @catch.CatchID = int.Parse(set.Tables[0].Rows[0]["CatchID"].ToString());
                }
                @catch.CatchName = set.Tables[0].Rows[0]["CatchName"].ToString();
                if (set.Tables[0].Rows[0]["IsUsing"].ToString() != "")
                {
                    @catch.IsUsing = int.Parse(set.Tables[0].Rows[0]["IsUsing"].ToString());
                }
                @catch.Url = set.Tables[0].Rows[0]["Url"].ToString();
                if (set.Tables[0].Rows[0]["StartPage"].ToString() != "")
                {
                    @catch.StartPage = int.Parse(set.Tables[0].Rows[0]["StartPage"].ToString());
                }
                if (set.Tables[0].Rows[0]["EndPage"].ToString() != "")
                {
                    @catch.EndPage = int.Parse(set.Tables[0].Rows[0]["EndPage"].ToString());
                }
                if (set.Tables[0].Rows[0]["CurPage"].ToString() != "")
                {
                    @catch.CurPage = int.Parse(set.Tables[0].Rows[0]["CurPage"].ToString());
                }
                if (set.Tables[0].Rows[0]["Interval"].ToString() != "")
                {
                    @catch.Interval = int.Parse(set.Tables[0].Rows[0]["Interval"].ToString());
                }
                if (set.Tables[0].Rows[0]["State"].ToString() != "")
                {
                    @catch.State = int.Parse(set.Tables[0].Rows[0]["State"].ToString());
                }
                if (set.Tables[0].Rows[0]["LastTime"].ToString() != "")
                {
                    @catch.LastTime = DateTime.Parse(set.Tables[0].Rows[0]["LastTime"].ToString());
                }
                if (set.Tables[0].Rows[0]["CurTimes"].ToString() != "")
                {
                    @catch.CurTimes = int.Parse(set.Tables[0].Rows[0]["CurTimes"].ToString());
                }
                if (set.Tables[0].Rows[0]["AllTimes"].ToString() != "")
                {
                    @catch.AllTimes = int.Parse(set.Tables[0].Rows[0]["AllTimes"].ToString());
                }
                if (set.Tables[0].Rows[0]["NodeID"].ToString() != "")
                {
                    @catch.NodeID = int.Parse(set.Tables[0].Rows[0]["NodeID"].ToString());
                }
                @catch.NodeName = set.Tables[0].Rows[0]["NodeName"].ToString();
                if (set.Tables[0].Rows[0]["SiteID"].ToString() != "")
                {
                    @catch.SiteID = int.Parse(set.Tables[0].Rows[0]["SiteID"].ToString());
                }
                if (set.Tables[0].Rows[0]["ServerID"].ToString() != "")
                {
                    @catch.ServerID = int.Parse(set.Tables[0].Rows[0]["ServerID"].ToString());
                }
                @catch.Whilelist = set.Tables[0].Rows[0]["Whilelist"].ToString();
                @catch.Blacklist = set.Tables[0].Rows[0]["Blacklist"].ToString();
                @catch.ContentPlus = set.Tables[0].Rows[0]["ContentPlus"].ToString();
                if (set.Tables[0].Rows[0]["SavePic"].ToString() != "")
                {
                    @catch.SavePic = int.Parse(set.Tables[0].Rows[0]["SavePic"].ToString());
                }
                if (set.Tables[0].Rows[0]["ContentType"].ToString() != "")
                {
                    @catch.ContentType = int.Parse(set.Tables[0].Rows[0]["ContentType"].ToString());
                }
                if (set.Tables[0].Rows[0]["ParseID"].ToString() != "")
                {
                    @catch.ParseID = int.Parse(set.Tables[0].Rows[0]["ParseID"].ToString());
                }
                @catch.ParseName = set.Tables[0].Rows[0]["ParseName"].ToString();
                if (set.Tables[0].Rows[0]["CreateTime"].ToString() != "")
                {
                    @catch.CreateTime = DateTime.Parse(set.Tables[0].Rows[0]["CreateTime"].ToString());
                }
                if (set.Tables[0].Rows[0]["UpdateTime"].ToString() != "")
                {
                    @catch.UpdateTime = DateTime.Parse(set.Tables[0].Rows[0]["UpdateTime"].ToString());
                }
                return @catch;
            }
            return null;
        }

        public int Update(KeRui.Model.CmsCatch model)
        {
            int num;
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@CatchID", SqlDbType.Int, 4), new SqlParameter("@CatchName", SqlDbType.NVarChar, 50), new SqlParameter("@IsUsing", SqlDbType.Int, 4), new SqlParameter("@Url", SqlDbType.VarChar, 0xff), new SqlParameter("@StartPage", SqlDbType.Int, 4), new SqlParameter("@EndPage", SqlDbType.Int, 4), new SqlParameter("@Interval", SqlDbType.Int, 4), new SqlParameter("@NodeID", SqlDbType.Int, 4), new SqlParameter("@Whilelist", SqlDbType.NVarChar), new SqlParameter("@Blacklist", SqlDbType.NVarChar), new SqlParameter("@SavePic", SqlDbType.Int, 4), new SqlParameter("@ParseID", SqlDbType.Int, 4), new SqlParameter("@ContentType", SqlDbType.Int, 4), new SqlParameter("@ContentPlus", SqlDbType.NVarChar) };
            parameters[0].Value = model.CatchID;
            parameters[1].Value = model.CatchName;
            parameters[2].Value = model.IsUsing;
            parameters[3].Value = model.Url;
            parameters[4].Value = model.StartPage;
            parameters[5].Value = model.EndPage;
            parameters[6].Value = model.Interval;
            parameters[7].Value = model.NodeID;
            parameters[8].Value = model.Whilelist;
            parameters[9].Value = model.Blacklist;
            parameters[10].Value = model.SavePic;
            parameters[11].Value = model.ParseID;
            parameters[12].Value = model.ContentType;
            parameters[13].Value = model.ContentPlus;
            return DbHelperSQL.RunProcedure("CmsCatch_Update", parameters, out num);
        }
    }
}

